import json


class JsonMixin:
    def to_json(self):
        return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)

class Product(JsonMixin):
    def __init__(self, name, price):
        self.name = name
        self.price = price

product = Product("apple", 10)


print(product.to_json())